//
//  BADSuccessViewController.m
//  BAD
//
//  Created by Can on 2018/5/15.
//  Copyright © 2018年 hwd. All rights reserved.
//

#import "BADSuccessViewController.h"
#import "BADScanViewController.h"
#import "BADLinkViewController.h"

@interface BADSuccessViewController ()

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSString *strDHA;
@property (nonatomic, strong) NSString *product;
@property (nonatomic, strong) NSString *suitable;
@property (nonatomic, strong) NSString *specification;
@property (nonatomic, strong) NSString *contain;
@property (nonatomic, strong) NSString *strUrl;

@end

@implementation BADSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    
    [self creatTableView];
    
    [self getString];
    
    [self creatView];
}

- (void)creatTableView
{
    CGFloat height = StatusBarHeight;
    
    UIImageView *imageView = [UIViewControls creatImageView:CGRectMake(0, -height, SCREENW, SCREENH + height) imageName:@"bg"];
    [self.view addSubview:imageView];
    imageView.userInteractionEnabled = YES;
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH + height) style:UITableViewStylePlain];
    [imageView addSubview:_tableView];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
}

- (void)creatView
{
    UIView *headView = [UIView new];
    headView.backgroundColor = [UIColor clearColor];
    
    UIImageView *bioisland = [UIViewControls creatImageView:CGRectMake((SCREENW - 292/2*screenW_6)/2, 161/2*screenW_6, 292/2*screenW_6, 105/2*screenW_6) imageName:@"logo3"];
    [headView addSubview:bioisland];
    
    UIImageView *backImageView = [UIViewControls creatImageView:CGRectMake(SCREENW - 25*screenW_6 - 35*screenW_6, 105/2*screenW_6, 35*screenW_6, 35*screenW_6) imageName:@"close2"];
    [headView addSubview:backImageView];
    backImageView.userInteractionEnabled = YES;
    //添加点击手势（即点击图片后退出全屏）
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
    [backImageView addGestureRecognizer:tapGesture];
    
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(15*screenW_6, CGRectGetMaxY(bioisland.frame) + 128/2*screenW_6, SCREENW - 30*screenW_6, 300)];
    backView.backgroundColor = [UIColor whiteColor];
    backView.layer.cornerRadius = 8;
    backView.layer.masksToBounds = YES;
    [self creatBackView:backView rect:backView.frame];
    
    headView.frame = CGRectMake(0, 0, SCREENW, CGRectGetMaxY(backView.frame) + 45*screenW_6);
    
    [headView addSubview:backView];
    
    [_tableView setTableHeaderView:headView];
}

- (void)closeView
{
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[BADScanViewController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

- (UIView *)creatBackView:(UIView *)backView rect:(CGRect)rect
{
    UIImageView *successImg = [UIViewControls creatImageView:CGRectMake((backView.width - 103/2*screenW_6)/2, 47/2*screenW_6, 103/2*screenW_6, 103/2*screenW_6) imageName:@"icon04"];
    [backView addSubview:successImg];
    
    UILabel *successLable = [UIViewControls creatLable:CGRectMake(0, CGRectGetMaxY(successImg.frame) + 20*screenW_6, backView.width, 16*screenW_6) text:@"Verification Successful" textColor:[UIColor colorWithHexString:@"#3088fb"] textFont:[UIFont systemFontOfSize:15.28*screenW_6]];
    [backView addSubview:successLable];
    
    UILabel *please = [UIViewControls creatLable:CGRectMake(0, CGRectGetMaxY(successLable.frame) + 15*screenW_6, backView.width, 14*screenW_6) text:@"Please see the product details below" textColor:[UIColor colorWithHexString:@"#bbb9b9"] textFont:[UIFont systemFontOfSize:13.22*screenW_6]];
    [backView addSubview:please];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(10*screenW_6, CGRectGetMaxY(please.frame) + 47/2*screenW_6, backView.width - 20*screenW_6, 1)];
    line.backgroundColor = [UIColor colorWithHexString:@"#bbb9b9"];
    [backView addSubview:line];
    
    UIImageView *dha = [UIViewControls creatImageView:CGRectMake((backView.width - 150*screenW_6)/2, CGRectGetMaxY(line.frame), 150*screenW_6, 150*screenW_6) imageName:[NSString stringWithFormat:@"%@",_ID]];
    [backView addSubview:dha];
    
    UILabel *dhaLable = [UIViewControls creatLable:CGRectMake(104/2*screenW_6, CGRectGetMaxY(dha.frame), backView.width - 104*screenW_6, 55/2*screenW_6) text:_strDHA textColor:[UIColor colorWithHexString:@"#999999"] textFont:[UIFont systemFontOfSize:12*screenW_6]];
    dhaLable.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
    dhaLable.layer.cornerRadius = 8;
    dhaLable.layer.masksToBounds = YES;
    [backView addSubview:dhaLable];
    dhaLable.frame = CGRectMake(104/2*screenW_6, CGRectGetMaxY(dha.frame), backView.width - 104*screenW_6, [UIViewControls lableHeight:dhaLable] + 12*screenW_6);
    
    UILabel *product = [self creatLable:CGRectMake(104/2*screenW_6, CGRectGetMaxY(dhaLable.frame) + 21/2*screenW_6, backView.width - 104*screenW_6, 10*screenW_6) text:_product];
    [backView addSubview:product];
    product.frame = CGRectMake(104/2*screenW_6, CGRectGetMaxY(dhaLable.frame) + 21/2*screenW_6, backView.width - 104*screenW_6, [UIViewControls lableHeight:product]);
    
    UILabel *suitable = [self creatLable:CGRectMake(104/2*screenW_6, CGRectGetMaxY(product.frame) + 7*screenW_6, backView.width - 104*screenW_6, 10*screenW_6) text:_suitable];
    [backView addSubview:suitable];
    suitable.frame = CGRectMake(104/2*screenW_6, CGRectGetMaxY(product.frame) + 21/2*screenW_6, backView.width - 104*screenW_6, [UIViewControls lableHeight:suitable]);
    
    UILabel *productSpec = [self creatLable:CGRectMake(104/2*screenW_6, CGRectGetMaxY(suitable.frame) + 7*screenW_6, backView.width - 104*screenW_6, 10*screenW_6) text:_specification];
    [backView addSubview:productSpec];
    productSpec.frame = CGRectMake(104/2*screenW_6, CGRectGetMaxY(suitable.frame) + 21/2*screenW_6, backView.width - 104*screenW_6, [UIViewControls lableHeight:productSpec]);
    
    UILabel *contains = [self creatLable:CGRectMake(104/2*screenW_6, CGRectGetMaxY(productSpec.frame) + 7*screenW_6, backView.width - 104*screenW_6, 10*screenW_6) text:_contain];
    [backView addSubview:contains];
    contains.frame = CGRectMake(104/2*screenW_6, CGRectGetMaxY(productSpec.frame) + 21/2*screenW_6, backView.width - 104*screenW_6, [UIViewControls lableHeight:contains]);

    UIButton *more = [UIViewControls creatButtonBackImage:CGRectMake((backView.width - 294/2*screenW_6)/2, CGRectGetMaxY(contains.frame) + 58/2*screenW_6, 294/2*screenW_6, 94/2*screenW_6) imageName:@"button01"];
    [more addTarget:self action:@selector(moreCloseView:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:more];
    
    backView.frame = CGRectMake(rect.origin.x, rect.origin.y, SCREENW - 30*screenW_6, CGRectGetMaxY(more.frame) + 58/2*screenW_6);
    
    return backView;
}

- (void)getString
{
    switch ([_ID integerValue]) {
        case 3:{
            _strDHA = @"Kangaroo Essence 50000";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Adults";
            _specification = @"Product Specification：90 vege capsules";
            _contain = @"";
            _strUrl = @"http://www.bioisland.com.au/products/adults-range/kangaroo-essence-50000/";
        }
            
            
            break;
            
        case 4:{
            _strDHA = @"DHA for kids";
            _product = @"Country of  origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Infants and children";
            _specification = @"Product Specification：60 softgel capsules";
            _contain = @"";
            _strUrl = @"http://www.bioisland.com.au/products/kids-range/dha-for-kids/";
        }
            
            
            break;
            
        case 5:{
            _strDHA = @"DHA for Pregnancy";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Adults including women trying to conceive， pregnant women and breastfeeding mothers.";
            _specification = @"Product Specification：60 capsules";
            _contain = @"";
            _strUrl = @"http://www.bioisland.com.au/products/adults-range/dha-for-pregnancy/";
        }
            
            
            break;
            
        case 6:{
            _strDHA = @"Zinc";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：children";
            _specification = @"Product Specification：120 chewable tablets";
            _contain = @"*Contains milk,glucose and sucralose.";
            _strUrl = @"http://www.bioisland.com.au/products/kids-range/zinc/";
        }
            
            
            break;
            
        case 7:{
            _strDHA = @"Milk Calcium for kid";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Infants and children";
            _specification = @"Product Specification：90 softgel capsules";
            _contain = @"*Contains milk and soya bean products.";
            _strUrl = @"http://www.bioisland.com.au/products/kids-range/milk-calcium-for-kids/";
        }
            
            
            break;
            
        case 8:{
            _strDHA = @"Cod Liver + Fish Oil for kids";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Infants and children";
            _specification = @"Product Specification：90 softgel capsules";
            _contain = @"";
            _strUrl = @"http://www.bioisland.com.au/products/kids-range/cod-liver-plus-fish-oil-for-kids/";
        }
            
            
            break;
            
        case 9:{
            _strDHA = @"Lysine Step Up for Youth";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：children and adolescents";
            _specification = @"Product Specification：60 chewable tablets";
            _contain = @"* Contains milk,lactose and sucralose.";
            _strUrl = @"http://www.bioisland.com.au/products/kids-range/lysine-step-up-for-youth/";
        }
            
            
            break;
            
        case 10:{
            _strDHA = @"Milk Calcium Bone Care";
            _product = @"Country of origin：Made in New Zealand.";
            _suitable = @"Suitable for：Adolescents，Adults including pregnant women，breastfeeding women.";
            _specification = @"Product specification：150 softgel capsules";
            _contain = @"*Contains milk and soya bean products.";
            _strUrl = @"http://www.bioisland.com.au/products/adults-range/milk-calcium-bone-care/";
        }
            
            
            break;
            
        case 11:{
            _strDHA = @"Eyesight Support";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Adults";
            _specification = @"Product Specification：180 softgel capsules";
            _contain = @"";
            _strUrl = @"http://www.bioisland.com.au/products/adults-range/eyesight-support/";
        }
            
            
            break;
            
        case 12:{
            _strDHA = @"Lysine Starter for kids";
            _product = @"Country of origin：Manufactured in Australia form local and imported ingredients.";
            _suitable = @"Suitable for：Infants and children";
            _specification = @"Product specification：150g oral powder";
            _contain = @"* Contains milk.";
            _strUrl = @"http://www.bioisland.com.au/products/kids-range/lysine-starter-for-kids/";
        }
            
            
            break;
            
        case 13:{
            _strDHA = @"Super C Chews";
            _product = @"Country of origin：Made in New Zealand";
            _suitable = @"Suitable for：Children over 1 year old，pregnant and adults. For children under 3 years, please crumble the tablet before chewing. ";
            _specification = @"Product specification：200 chewbale tablets";
            _contain = @"";
            _strUrl = @"http://www.bioisland.com.au/products/lifestyle-range/super-c-chews/";
        }
            
            break;

        default:
            break;
    }
}

- (UILabel *)creatLable:(CGRect)rect text:(NSString *)text
{
    UILabel *lable = [[UILabel alloc]initWithFrame:rect];
    lable.text = text;
    lable.textColor = [UIColor colorWithHexString:@"#7b7b7b"];
    lable.font = [UIFont systemFontOfSize:10*screenW_6];
    lable.textAlignment = NSTextAlignmentLeft;
    return lable;
}


-(void)moreCloseView:(UIButton *)btn{
    BADLinkViewController *linkVC = [BADLinkViewController new];
    linkVC.strUrl = _strUrl;
    [self.navigationController pushViewController:linkVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
